package com.scada.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.scada.dao.IMemberPlanBuyDao;
import com.scada.inf.MemberPlanBuyVisitor;
import com.scada.model.bean.MemberPlanBuy;
import com.scada.model.result.ResponseBean;
import com.scada.model.search.MemberPlanBuySearch;

@Service("memberPlanBuyVisitorService")
@WebService
@SOAPBinding(style = Style.RPC)
public class MemberPlanBuyVisitorImpl implements MemberPlanBuyVisitor{

	@Autowired
	private IMemberPlanBuyDao memberPlanBuyDao;
	
	@Override
	@Transactional
	public void deleteMemberPlanBuyById(String isShow, String ids) {
		
		try {
			Map<String,Object> map = null;
			for(String id : ids.split(",")) {
				map = new HashMap<String,Object>(); 
				map.put("isShow", isShow);
				map.put("id", Long.parseLong(id));
				memberPlanBuyDao.deleteMemberPlanBuyById(map);
			}
		}catch (Exception e) {
			throw new RuntimeException();
		}
	}

	@Override
	public ResponseBean insertMemberPlanBuy(MemberPlanBuy memberPlanBuy) {
		
		ResponseBean responseBean = new ResponseBean();
		try{
			memberPlanBuyDao.insertMemberPlanBuy(memberPlanBuy);
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean getMemberPlanBuyById(Long id) {
		
		ResponseBean responseBean = new ResponseBean();
		try{
			responseBean.addObject("result", memberPlanBuyDao.getMemberPlanBuyById(id));
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean updateMemberPlanBuy(MemberPlanBuy memberPlanBuy) {
		
		ResponseBean responseBean = new ResponseBean();
		try{
			memberPlanBuyDao.updateMemberPlanBuy(memberPlanBuy);
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean getMemberPlanBuyPageData(MemberPlanBuySearch memberPlanBuySearch) {
		
		ResponseBean responseBean = new ResponseBean();
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			map.put("isShow", MemberPlanBuy.IsShowCode.YES.getKey());
			map.put("serviceId", memberPlanBuySearch.getServiceId());
			map.put("memberId", memberPlanBuySearch.getMemberId());
			map.put("planStartDate", memberPlanBuySearch.getPlanStartDate());
			map.put("planEndDate", memberPlanBuySearch.getPlanStartDate());
			map.put("serviceType", memberPlanBuySearch.getServiceType());
			responseBean.addObject("resultCount", memberPlanBuyDao.getMemberPlanBuyPageCount(map));
			map.put("start", memberPlanBuySearch.getStart());
			map.put("pageSize", memberPlanBuySearch.getLength());
            responseBean.addObject("resultList", memberPlanBuyDao.getMemberPlanBuyPageList(map));
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}


}
